<%@ page session="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<jsp:include page="../cabecera_home.jsp"></jsp:include>

<div class="cuerpo" align="center">
	<br>
	<div class="marco_publicacion" align="left">

		<script src="static/scripts/jquery.js"></script>
		<script>
			$(document).ready(function() {
				$(".barra_info_titulo").click(function() {
					$(".barra_info_stock").slideToggle("slow");
				});
				$(".buscar_productos_titulo").click(function() {
					$(".datos_stock").slideToggle("slow");
				});
			});
		</script>

		<b class="publicacion_titulo">Stocks</b><br>
		<c:if test="${not empty mis_empresas}">
			<hr>
			<div class="barra_info_titulo">
				<b class="publicacion_titulo2">Mis Productos</b>
			</div>
			<form:form method="post" modelAttribute="mis_empresas">
				<c:forEach items="${mis_empresas}" var="empresa">
					<div class="barra_info_stock">
						<div class="barra_info_stock_razon" align="left">${empresa.razonSocial}</div>
						<div class="vertical"></div>
						<a href="stocks_listar?id=${empresa.id}">
							<div class="barra_info_stock_ver" align="center">Ver Stock</div>
						</a> <a href="stock_alta?id=${empresa.id}"><div
								class="barra_info_stock_cargar" align="center">+ Cargar
								Producto</div></a>
						<div style="clear: both"></div>
					</div>

				</c:forEach>

			</form:form>
		</c:if>
		<hr>
		<div class="buscar_productos_titulo">
			<b class="publicacion_titulo2">Buscar Productos</b>
		</div>
		<div class="datos_stock">
			<form:form modelAttribute="busquedaVinosDTO" action="busqueda_vinos"
				method="post">

				<p>
				<h3>Variedad</h3>
				<form:select class="select_text_desc" path="variedad">
					<form:options items="${variedades}" />
				</form:select>
				</p>
				<p>
				<h3>Nivel de Azucar</h3>
				<form:input class="registro_emp_text" path="azucar"
					placeholder="Ej: 14" />
				</p>
				<p>
					<form:errors path="azucar" />
				</p>
				<p>
				<h3>Nivel de Acidez</h3>
				<form:input class="registro_emp_text" path="acidez"
					placeholder="Ej: 25" />
				</p>
				<p>
					<form:errors path="acidez" />
				</p>
				<p>
				<h3>Color</h3>
				<form:input class="registro_emp_text" path="color"
					placeholder="Ej: 200" />
				</p>
				<p>
					<form:errors path="color" />
				</p>
				<p>
				<h3>Grado de Alcohol</h3>
				<form:input class="registro_emp_text" path="alcohol"
					placeholder="Ej: 12" />
				</p>
				<p>
					<form:errors path="alcohol" />
				</p>

				<input type="submit" class="registro_emp_submit" value="Buscar">

			</form:form>
		</div>
		
		
		<c:if test="${not empty resultList}">
			<hr>
			<table>
				<table>
					<caption>Resultados de la Busqueda</caption>
					<thead>
						<tr>
							<th scope="col">Azucar</th>
							<th scope="col">Acidez</th>
							<th scope="col">Color</th>
							<th scope="col">Alcohol</th>
							<th scope="col">Variedad</th>
							<th scope="col">Cantidad</th>
							<th scope="col">Creado</th>
							<th scope="col">Vencimiento</th>
							<th scope="col">Estado</th>
							<th scope="col">Detalles</th>
						</tr>
					</thead>
					<tfoot>
						<th scope="row">Total</th>
						<td colspan="10">${resultList.size()} resultados encontrados</td>
					</tfoot>
					<tbody>
						<c:forEach items="${resultList}" var="stock">
							<tr>
								<th scope="row">${stock.azucar}</th>
								<td scope="row">${stock.acidez}</td>
								<td scope="row">${stock.color}</td>
								<td scope="row">${stock.alcohol}</td>
								<td scope="row">${stock.variedad}</td>
								<td scope="row">${stock.cantidad}</td>
								<td scope="row"><fmt:formatDate
										value="${stock.fechaCreacionStock}" pattern="MM/dd/yyyy"
										timeZone="GMT" /></td>
								<td scope="row"><fmt:formatDate
										value="${stock.vencimiento}" pattern="MM/dd/yyyy"
										timeZone="GMT" /></td>

								<c:choose>
									<c:when test='${stock.fechaVenta != null}'>
										<td scope="row"><span style="color: red;">Vendido</span></td>
									</c:when>
									<c:otherwise>
										<td scope="row"><span style="color: green;">Disponible</span></td>
									</c:otherwise>
								</c:choose>
								<td scope="row"><a href="stocks_detalle?id=${stock.id}">VER</a></td>
							</tr>

						</c:forEach>
					</tbody>
				</table>
		</c:if>

	</div>
	<br>
</div>

<jsp:include page="../pie_de_pagina_compartida.jsp"></jsp:include>
